package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlQuizStatistics entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlQuizStatistics
 * @author MyEclipse Persistence Tools
 */

public class MdlQuizStatisticsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlQuizStatisticsDAO.class);
	// property constants
	public static final String QUIZID = "quizid";
	public static final String GROUPID = "groupid";
	public static final String ALLATTEMPTS = "allattempts";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String FIRSTATTEMPTSCOUNT = "firstattemptscount";
	public static final String ALLATTEMPTSCOUNT = "allattemptscount";
	public static final String FIRSTATTEMPTSAVG = "firstattemptsavg";
	public static final String ALLATTEMPTSAVG = "allattemptsavg";
	public static final String MEDIAN = "median";
	public static final String STANDARDDEVIATION = "standarddeviation";
	public static final String SKEWNESS = "skewness";
	public static final String KURTOSIS = "kurtosis";
	public static final String CIC = "cic";
	public static final String ERRORRATIO = "errorratio";
	public static final String STANDARDERROR = "standarderror";

	public void save(MdlQuizStatistics transientInstance) {
		log.debug("saving MdlQuizStatistics instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlQuizStatistics persistentInstance) {
		log.debug("deleting MdlQuizStatistics instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlQuizStatistics findById(java.lang.Long id) {
		log.debug("getting MdlQuizStatistics instance with id: " + id);
		try {
			MdlQuizStatistics instance = (MdlQuizStatistics) getSession().get(
					"idv.loveloser.dao.MdlQuizStatistics", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlQuizStatistics instance) {
		log.debug("finding MdlQuizStatistics instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlQuizStatistics")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlQuizStatistics instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlQuizStatistics as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByQuizid(Object quizid) {
		return findByProperty(QUIZID, quizid);
	}

	public List findByGroupid(Object groupid) {
		return findByProperty(GROUPID, groupid);
	}

	public List findByAllattempts(Object allattempts) {
		return findByProperty(ALLATTEMPTS, allattempts);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByFirstattemptscount(Object firstattemptscount) {
		return findByProperty(FIRSTATTEMPTSCOUNT, firstattemptscount);
	}

	public List findByAllattemptscount(Object allattemptscount) {
		return findByProperty(ALLATTEMPTSCOUNT, allattemptscount);
	}

	public List findByFirstattemptsavg(Object firstattemptsavg) {
		return findByProperty(FIRSTATTEMPTSAVG, firstattemptsavg);
	}

	public List findByAllattemptsavg(Object allattemptsavg) {
		return findByProperty(ALLATTEMPTSAVG, allattemptsavg);
	}

	public List findByMedian(Object median) {
		return findByProperty(MEDIAN, median);
	}

	public List findByStandarddeviation(Object standarddeviation) {
		return findByProperty(STANDARDDEVIATION, standarddeviation);
	}

	public List findBySkewness(Object skewness) {
		return findByProperty(SKEWNESS, skewness);
	}

	public List findByKurtosis(Object kurtosis) {
		return findByProperty(KURTOSIS, kurtosis);
	}

	public List findByCic(Object cic) {
		return findByProperty(CIC, cic);
	}

	public List findByErrorratio(Object errorratio) {
		return findByProperty(ERRORRATIO, errorratio);
	}

	public List findByStandarderror(Object standarderror) {
		return findByProperty(STANDARDERROR, standarderror);
	}

	public List findAll() {
		log.debug("finding all MdlQuizStatistics instances");
		try {
			String queryString = "from MdlQuizStatistics";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlQuizStatistics merge(MdlQuizStatistics detachedInstance) {
		log.debug("merging MdlQuizStatistics instance");
		try {
			MdlQuizStatistics result = (MdlQuizStatistics) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlQuizStatistics instance) {
		log.debug("attaching dirty MdlQuizStatistics instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlQuizStatistics instance) {
		log.debug("attaching clean MdlQuizStatistics instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}